home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / clue.lha / clue / examples / old / valuators.l < prev   
Encoding:
Text File  |  1989-07-12  |  27.1 KB  |  774 lines

  1. ;;; -*- Mode:Lisp; Package:CLUE-EXAMPLES; Lowercase:T; Base:10; Syntax:Common-Lisp -*-
  2. ;;;
  3. ;;;             TEXAS INSTRUMENTS INCORPORATED
  4. ;;;                  P.O. BOX 2909
  5. ;;;                   AUSTIN, TEXAS 78769
  6. ;;;
  7. ;;; Copyright (C) 1988 Texas Instruments Incorporated.
  8. ;;;
  9. ;;; Permission is granted to any individual or institution to use, copy, modify,
  10. ;;; and distribute this software, provided that this complete copyright and
  11. ;;; permission notice is maintained, intact, in all copies and supporting
  12. ;;; documentation.
  13. ;;;
  14. ;;; Texas Instruments Incorporated provides this software "as is" without
  15. ;;; express or implied warranty.
  16. ;;;
  17.  
  18. ;;;
  19. ;;; Description:  Valuator contacts
  20. ;;;
  21. ;;; Change History: 
  22. ;;; ----------------------------------------------------------------------------
  23. ;;; 10/27/87   KK    Created
  24. ;;;  6/09/88   KK    Updated to TICLOS v7, CLUE v13
  25. ;;;  6/14/88   KK    Removed scale, use floating pt value range
  26. ;;;  6/21/88   KK    Added precision slot
  27. ;;;  7/15/88   SLM   Add call to '(the VALUATOR self)' in VALUATOR-SET-BY-USER
  28. ;;;  8/26/88   SLM   Changed doc strings to be useful for the mouse-documentation window
  29.  
  30.  
  31. ;;;----------------------------------------------------------------------------------+
  32. ;;;                                                                                  |
  33. ;;;                                     valuator                                     |
  34. ;;;                                                                                  |
  35. ;;;----------------------------------------------------------------------------------+
  36.  
  37. (in-package 'clue-examples :use '(lisp xlib clos cluei))
  38.  
  39.  
  40.  
  41. (defcontact valuator (contact)
  42.   ((fg-color        :type      pixel
  43.             :initarg   :fg-color
  44.             :accessor  fg-color
  45.             :initform  0
  46.                     )
  47.    (bg-color        :type      pixel
  48.             :initarg   :bg-color
  49.             :accessor  bg-color
  50.             :initform  1
  51.                     )
  52.    (minimum         :type      number
  53.             :initarg   :minimum
  54.             :accessor  valuator-minimum
  55.             :initform  0)
  56.    (maximum         :type      number
  57.             :initarg   :maximum
  58.             :accessor  valuator-maximum
  59.             :initform  0)
  60.    (value           :type      number
  61.             :initarg   :value
  62.             :accessor  valuator-value
  63.             :initform  0)
  64.    (indicator-size  :type      number
  65.             :initarg   :indicator-size
  66.             :accessor  valuator-indicator-size
  67.             :initform  1)
  68.    (increment       :type      number
  69.             :initarg   :increment
  70.             :accessor  valuator-increment
  71.             :initform  1)
  72.    (precision       :type      (or null number)
  73.             :initarg   :precision
  74.             :accessor  valuator-precision
  75.             :initform  1)
  76.    (documentation   :initform   "L: more  M: move to here  R: less")) 
  77.   (:resources       increment
  78.             fg-color
  79.             bg-color
  80.             documentation
  81.             (event-mask :initform #.(make-event-mask :pointer-motion-hint)))
  82.   (:documentation   "A basic valuator which controls a numeric value."))
  83.  
  84.  
  85. (proclaim '(inline precision-round))
  86. (defun precision-round (value precision)
  87.   (if precision
  88.       (* precision (round value precision))
  89.       value))
  90.  
  91.  
  92.  
  93. ;;;  Setting values
  94.  
  95. (defmethod initialize-instance :after ((self valuator) &key &allow-other-keys)  
  96.   ;; Ensure that indicator is initialized
  97.   (valuator-change-indicator self (valuator-indicator-size self)))
  98.  
  99. (defmethod (setf valuator-minimum) (min (self valuator))
  100.   (valuator-calibrate self :minimum min))
  101.  
  102. (defmethod (setf valuator-maximum) (max (self valuator))
  103.   (valuator-calibrate self :maximum max))
  104.  
  105. (defmethod (setf valuator-indicator-size) (new-size (self valuator))
  106.   (valuator-calibrate self :indicator-size new-size))
  107.  
  108. (defmethod (setf valuator-value) (new-value (self valuator))
  109.   (with-slots (maximum minimum) self
  110.     (unless (and (<= new-value maximum) (>= new-value minimum))
  111.     (error "Invalid value: ~a is not in the range (~a ~a)." new-value minimum maximum)))
  112.   (valuator-calibrate self :value new-value))
  113.     
  114. (defmethod valuator-calibrate ((self valuator) &key minimum maximum value indicator-size)
  115.   (with-slots ((slot-minimum minimum)
  116.                (slot-maximum maximum)
  117.                (slot-value value)
  118.                (slot-indicator-size indicator-size))
  119.               self
  120.     ;; Set default argument values
  121.     (setf minimum        (or minimum slot-minimum)
  122.       maximum        (or maximum slot-maximum)
  123.       indicator-size (or indicator-size slot-indicator-size)
  124.       value          (max (min (or value slot-value) maximum) minimum))
  125.       
  126.     (let* ((range-changed     (or (/= minimum slot-minimum)
  127.                   (/= maximum slot-maximum)
  128.                   (/= indicator-size slot-indicator-size)))
  129.        (value-changed     (/= value slot-value)))
  130.       
  131.       ;; Erase previous indicator
  132.       (when (realized-p self) (valuator-erase-indicator self))
  133.       
  134.       (when  range-changed
  135.     ;; Check for valid range
  136.     (assert (<= minimum maximum)
  137.         nil "Minimum (~a) exceeds maximum (~a)."
  138.         minimum  maximum)    
  139.     
  140.     ;; Adjust internal conversions for new range and indicator size
  141.     (valuator-adjust-size self minimum maximum indicator-size)
  142.     (valuator-change-indicator self indicator-size))
  143.  
  144.       ;; Update instance variables
  145.       (setf slot-minimum        minimum
  146.         slot-maximum        maximum
  147.         slot-value          value
  148.         slot-indicator-size indicator-size)
  149.       
  150.       ;; Reposition indicator
  151.       (valuator-move-indicator self value)
  152.  
  153.       ;; Redisplay, if necessary
  154.       (when (realized-p self) (display self))
  155.  
  156.       ;; Report program-requested value change 
  157.       (if value-changed (apply-callback self :changed-by-program value)))))
  158.  
  159.  
  160. (defmethod valuator-adjust-size ((self valuator) new-minimum new-maximum  new-indicator-size)
  161.   "Adjust the valuator size to new value range. The primary method for valuators is undefined."
  162.   (declare (ignore  new-minimum new-maximum  new-indicator-size)))
  163.  
  164.  
  165.  
  166. ;;; Indicator control
  167.  
  168. (defmethod valuator-change-indicator ((self valuator) new-indicator-size)
  169.   "Change the size of the valuator indicator.  NEW-INDICATOR-SIZE is given in the
  170. same units measure by the valuator."
  171.   (declare (ignore   new-indicator-size)))
  172.  
  173. (defmethod valuator-move-indicator ((self valuator) new-value)
  174.   "Change the indicator position to reflect the NEW-VALUE."
  175.   (declare (ignore new-value)))
  176.  
  177. (defmethod valuator-indicator-changed-p ((self valuator) new-value)
  178.   "Return true if setting NEW-VALUE will cause indicator display to change.
  179. This predicate is used to avoid unnecessary display updates."
  180.   (declare (ignore new-value))
  181.   t)
  182.  
  183. (defmethod valuator-display-indicator ((self valuator)))
  184. (defmethod valuator-erase-indicator ((self valuator)))
  185.  
  186. ;;; Actions
  187.  
  188.  
  189. (defmethod more ((self valuator))
  190.   "Initiate an operation to increment the valuator value.
  191. The primary valuator method does nothing. See FINISH-MORE.")
  192.  
  193. (defmethod finish-more ((self valuator))
  194.   "Conclude an operation to increment the valuator value."
  195.   (with-slots (value maximum increment) self
  196.       (when (< value maximum)
  197.         (valuator-set-by-user self (min (+ value increment) maximum)))))
  198.  
  199. (defmethod less ((self valuator))
  200.   "Initiate an operation to decrement the valuator value.
  201. The primary valuator method does nothing. See FINISH-LESS.")
  202.  
  203. (defmethod finish-less ((self valuator))
  204.   "Conclude an operation to decrement the valuator value."
  205.   (with-slots (value minimum increment) self
  206.     (when (> value minimum)
  207.       (valuator-set-by-user self (max (- value increment) minimum)))))
  208.  
  209. (defmethod here ((self valuator))
  210.   "Initiate an operation to directly position the valuator value.
  211. The primary valuator method does nothing. See FINISH-HERE.")
  212.  
  213. (defmethod finish-here ((self valuator))
  214.   "Conclude an operation to directly position the valuator value.
  215. The primary valuator method does nothing.")
  216.  
  217.  
  218.  
  219. ;;; Inquiry
  220.  
  221. (defmethod valuator-per-cent ((self valuator))
  222.   "Return the current value as a percentage of the total range (i.e. (- maximum minimum))."
  223.   (with-slots (value minimum maximum) self
  224.     (let ((range (- maximum minimum)))
  225.       (if (plusp range)
  226.       (float (/ (- value minimum) range))
  227.       1.0))))
  228.  
  229. ;;; Internal
  230. (defun valuator-set-by-user (self new-value)
  231.   ;; Echo new value
  232.   (when (valuator-indicator-changed-p self new-value)
  233.     (valuator-erase-indicator self)
  234.     (valuator-move-indicator self new-value)
  235.     (valuator-display-indicator self))
  236.   
  237.   (with-slots (value) (the valuator self)  ;;add '(THE valuator...) so kludged CLOS can macro expand correctly
  238.     ;; Change value
  239.     (setf value new-value)
  240.     
  241.     ;;Report new value
  242.     (apply-callback self :changed-by-user value)))
  243.  
  244.  
  245. ;;; Class bindings
  246.  
  247. (defevent valuator (:button-release :button-1) finish-more)
  248. (defevent valuator (:button-press   :button-1) more)
  249. (defevent valuator (:button-release :button-3) finish-less)
  250. (defevent valuator (:button-press   :button-3) less)
  251. (defevent valuator (:button-release :button-2) finish-here)
  252. (defevent valuator (:button-press   :button-2) move-here here)
  253. (defevent valuator (:motion-notify  :button-2) move-here)
  254.  
  255.  
  256. ;;;----------------------------------------------------------------------------------+
  257. ;;;                                                                                  |
  258. ;;;                                     scroller                                     |
  259. ;;;                                                                                  |
  260. ;;;----------------------------------------------------------------------------------+
  261.  
  262. (defvar *scroller-initial-delay*
  263.     0.35 "Seconds to delay before beginning continuous scrolling.")
  264. (defvar *scroller-delay*
  265.     0.10 "Seconds to delay before changing value during continuous scrolling.")
  266.  
  267. (defcontact scroller (valuator)
  268.   (;; Internal
  269.    (pixels-per-unit  :type number  :initform 0)
  270.    (thumb-position   :type integer :initform 0)
  271.    (thumb-size       :type integer :initform 0)  
  272.    (scroll-state               :initform :idle
  273.                   :type (member :idle :more :here :less :continuous-more :continuous-less))                   
  274.    (documentation :initform '(("L: more  M: move to here  R: less")
  275.                  ("Click-hold does the appropriate action continually"))))
  276.   (:resources documentation
  277.               fg-color
  278.               bg-color
  279.               fill-style)
  280.  
  281.   (:documentation    "A scroll bar valuator."))
  282.  
  283. (define-resources
  284.    (* scroller  * fg-color) 0
  285.    (* scroller  * bg-color) 1
  286.    (* scroller * fill-style) :opaque-stippled)
  287.  
  288. ;;; Indicator control
  289.  
  290. (defmethod valuator-change-indicator ((self scroller) new-indicator-size)
  291.   "Change the size of the scroller thumb.  NEW-INDICATOR-SIZE is given in the
  292. same units measure by the scroller."
  293.   (with-slots (thumb-size pixels-per-unit) self
  294.     (setf thumb-size (round (* new-indicator-size pixels-per-unit)))))
  295.  
  296. (defmethod valuator-move-indicator ((self scroller) new-value)
  297.   "Change the thumb position to reflect the NEW-VALUE."  
  298.   (with-slots (thumb-position pixels-per-unit minimum) self
  299.     (setf thumb-position (round (* pixels-per-unit (- new-value minimum))))))
  300.  
  301. (defmethod valuator-indicator-changed-p ((self scroller) new-value)
  302.   "Return true if setting NEW-VALUE will cause indicator display to change.
  303. This predicate is used to avoid unnecessary display updates."
  304.   (with-slots (thumb-position pixels-per-unit minimum) self
  305.     (/= thumb-position (round (* pixels-per-unit (- new-value minimum))))))
  306.  
  307. ;;; Display
  308.  
  309. (defmethod display ((self scroller) &optional x y width height &key)
  310.   (declare (ignore x y width height))
  311.   ;; Display thumb against background  
  312.   (valuator-display-indicator self))
  313.  
  314.  
  315. ;;; Actions
  316.  
  317. (defmethod more ((self scroller)) 
  318.   "Initiate an operation to increment the scroller value.
  319. This method implements the continuous scrolling feature."  
  320.   (with-slots (scroll-state value maximum increment) self
  321.     (when (eq scroll-state :idle)
  322.       (setf scroll-state :more)
  323.  
  324.       ;; Continuous scrolling loop
  325.       (do ((display (drawable-display self))
  326.         (delay   *scroller-initial-delay*))
  327.       ((and (process-next-event display delay)
  328.         (eq scroll-state :idle)))
  329.  
  330.     ;; Ensure continuous controlling scroll-state
  331.     (setf delay *scroller-delay*
  332.           scroll-state :continuous-more)
  333.  
  334.     (when (< value maximum)
  335.       (valuator-set-by-user self (min (+ value increment) maximum)))))))
  336.  
  337. (defmethod finish-more ((self scroller))
  338.   "Conclude an operation to increment the scroller value."
  339.   (with-event (y)
  340.     (with-slots (scroll-state value maximum minimum pixels-per-unit
  341.                        increment indicator-size precision) self
  342.       (case scroll-state
  343.         (:more
  344.          ;; Increment relative to event position
  345.      (when (< value maximum)
  346.            (valuator-set-by-user
  347.          self (min maximum
  348.                (+ value
  349.               (max increment
  350.                    (precision-round
  351.                  (* indicator-size (/ y (- maximum minimum) pixels-per-unit))
  352.                  precision))))))
  353.          
  354.          ;; Return to idle scroll-state
  355.          (setf scroll-state :idle))
  356.         
  357.         (:continuous-more
  358.          ;; Simply return to idle state
  359.          (setf scroll-state :idle))))))
  360.  
  361. (defmethod less ((self scroller))
  362.   "Initiate an operation to decrement the scroller value.
  363. This method implements the continuous scrolling feature."  
  364.   (with-slots (scroll-state value minimum increment) self
  365.     (when (eq scroll-state :idle)
  366.       (setf scroll-state :less)
  367.  
  368.       ;; Continuous scrolling loop
  369.       (do ((display (drawable-display self))
  370.         (delay   *scroller-initial-delay*))
  371.       ((and (process-next-event display delay)
  372.         (eq scroll-state :idle)))
  373.  
  374.     ;; Ensure continuous controlling state
  375.     (setf delay *scroller-delay*
  376.           scroll-state :continuous-less)
  377.  
  378.     (when (> value minimum)
  379.       (valuator-set-by-user self (max (- value increment) minimum)))))))
  380.  
  381. (defmethod finish-less ((self scroller))
  382.   "Conclude an operation to decrement the scroller value."
  383.   (with-event (y)
  384.     (with-slots (scroll-state value maximum minimum pixels-per-unit
  385.                        increment indicator-size precision) self
  386.       (case scroll-state
  387.         (:less
  388.          ;; Decrement relative to event position.
  389.          (when (> value minimum)
  390.            (valuator-set-by-user
  391.          self (max minimum
  392.                (- value
  393.               (max increment
  394.                    (precision-round
  395.                  (* indicator-size (/ y (- maximum minimum) pixels-per-unit))
  396.                  precision))))))
  397.          
  398.          ;; Return to idle scroll-state
  399.          (setf scroll-state :idle))
  400.         
  401.         (:continuous-less
  402.          ;; Simply return to idle state
  403.          (setf scroll-state :idle))))))
  404.  
  405.  
  406. (defmethod here ((self scroller))
  407.   "Initiate an operation to directly position the valuator value.
  408. This method implements the drag scrolling feature."  
  409.   (with-slots (scroll-state) self
  410.     (when (eq scroll-state :idle)
  411.       (setf scroll-state :here)
  412.  
  413.       ;; Drag scrolling loop
  414.       (do ((display (drawable-display self))
  415.         (delay  *scroller-initial-delay*))
  416.       ((and (process-next-event display delay)
  417.         (eq scroll-state :idle)))
  418.  
  419.     ;; Ensure continuous controlling state
  420.     (setf delay nil
  421.           scroll-state :continuous-here)))))
  422.  
  423. (defmethod finish-here ((self scroller))
  424.   "Conclude an operation to directly position the valuator value."
  425.   (with-slots (scroll-state) self
  426.     (if (eq scroll-state :here)
  427.     ;; Position according to finish event
  428.     (move-here self))
  429.     
  430.     ;; Return to idle state
  431.     (setf scroll-state :idle)))
  432.  
  433.  
  434.  
  435. ;;;----------------------------------------------------------------------------------+
  436. ;;;                                                                                  |
  437. ;;;                                     vscroller                                    |
  438. ;;;                                                                                  |
  439. ;;;----------------------------------------------------------------------------------+
  440.  
  441. (defcontact vscroller (scroller)
  442.   ()
  443.   (:documentation  "A vertically-oriented scroll bar valuator. "))
  444.  
  445.  
  446. ;;; Display
  447.  
  448. (defmethod valuator-display-indicator ((self vscroller))
  449.   (with-slots (fg-color bg-color thumb-position width height thumb-size) self
  450.     (using-gcontext (gcontext :drawable   self
  451.                   :foreground fg-color
  452.                   :background bg-color
  453.                   :fill-style :stippled 66%gray)
  454.       (draw-rectangle self gcontext
  455.               1 thumb-position
  456.               (max 1 (- width 2)) thumb-size
  457.               :fill-p)
  458.       (draw-rectangle self gcontext
  459.                       0 0 (- width 1) (- height 1)))))
  460.  
  461. (defmethod valuator-erase-indicator ((self vscroller))
  462.   (with-slots (thumb-position width thumb-size) self
  463.     (clear-area self
  464.         :y      thumb-position
  465.         :width  width
  466.         :height thumb-size)))
  467.  
  468. ;;; Size control
  469.  
  470. (defmethod valuator-adjust-size ((self vscroller) new-minimum new-maximum new-indicator-size)
  471.   "Adjust internal data for new range and indicator size"
  472.   (with-slots (height pixels-per-unit) self
  473.     (let ((range (- new-maximum new-minimum)))
  474.       (setf pixels-per-unit (/ height (if (plusp range) range new-indicator-size))))))
  475.  
  476.  
  477. ;;; Actions
  478.  
  479. (defmethod move-here ((self vscroller))
  480.   "Change value according to position given by the EVENT."
  481.  
  482.   ;; Use event to trigger a request for the current pointer position
  483.   (multiple-value-bind (x y) (query-pointer self)
  484.     (declare (ignore x))
  485.     (with-slots (value minimum maximum event-y pixels-per-unit precision) self
  486.       (let ((new-value (max (min (precision-round
  487.                    (+ minimum (/ y pixels-per-unit))
  488.                    precision)
  489.                                  maximum)
  490.                             minimum)))      
  491.         (when (/= new-value value)
  492.           (valuator-set-by-user self new-value))))))
  493.  
  494.  
  495.  
  496.  
  497.  
  498. ;;;----------------------------------------------------------------------------------+
  499. ;;;                                                                                  |
  500. ;;;                                     hscroller                                    |
  501. ;;;                                                                                  |
  502. ;;;----------------------------------------------------------------------------------+
  503.  
  504. (defcontact hscroller (scroller)
  505.   ()
  506.   (:documentation    "A horizontally-oriented scroll bar valuator."))
  507.  
  508.  
  509. ;;; Display
  510.  
  511. (defmethod valuator-display-indicator ((self hscroller))
  512.   (with-slots (fg-color bg-color thumb-position thumb-size height width) self
  513.     (using-gcontext (gcontext :drawable   self
  514.                   :foreground fg-color
  515.                   :background bg-color
  516.                   :fill-style :solid)
  517.       (draw-rectangle self gcontext
  518.               thumb-position 1
  519.               thumb-size (max 1 (- height 2))
  520.               :fill)
  521.       (draw-rectangle self gcontext
  522.                       0 0 (- width 1) (- height 1)))))
  523.  
  524. (defmethod valuator-erase-indicator ((self hscroller))
  525.   (with-slots (thumb-position thumb-size height) self
  526.     (clear-area self
  527.         :x      thumb-position
  528.         :width  thumb-size
  529.         :height height)))
  530.  
  531. ;;; Size control
  532.  
  533. (defmethod valuator-adjust-size ((self hscroller) new-minimum new-maximum new-indicator-size)
  534.   "Adjust internal data for new range and indicator size"
  535.   (with-slots (width pixels-per-unit) self
  536.     (let ((range (- new-maximum new-minimum)))
  537.       (setf pixels-per-unit (/ width (if (plusp range) range new-indicator-size))))))
  538.  
  539.  
  540. ;;; Actions
  541.  
  542. (defmethod move-here ((self hscroller))
  543.   "Change value according to position given by the EVENT."
  544.  
  545.   ;; Use event to trigger a request for the current pointer position
  546.   (multiple-value-bind (x y) (query-pointer self)
  547.     (declare (ignore y))
  548.     (with-slots (value minimum maximum event-y pixels-per-unit precision) self
  549.       (let ((new-value (max (min (precision-round
  550.                    (+ minimum (/ x pixels-per-unit))
  551.                    precision)
  552.                                  maximum)
  553.                             minimum)))      
  554.         (when (/= new-value value)
  555.           (valuator-set-by-user self new-value))))))
  556.  
  557.  
  558. ;;;----------------------------------------------------------------------------------+
  559. ;;;                                                                                  |
  560. ;;;                                     graduated-valuator                           |
  561. ;;;                                                                                  |
  562. ;;;----------------------------------------------------------------------------------+
  563.  
  564.  
  565.  
  566.  
  567. ;;;----------------------------------------------------------------------------------+
  568. ;;;                                                                                  |
  569. ;;;                                     slider                                       |
  570. ;;;                                                                                  |
  571. ;;;----------------------------------------------------------------------------------+
  572.  
  573. (defcontact slider (scroller)
  574.   (;; Internal
  575.    (thumb-pixmap     :type (or null pixmap) :initform nil))
  576.   (:documentation    "A slider valuator."))
  577.  
  578. ;;; Indicator control
  579.  
  580. (defmethod valuator-change-indicator ((self slider) new-indicator-size)
  581.   "Change the size of the slider thumb.  NEW-INDICATOR-SIZE is given in the
  582. same units measure by the slider."
  583.   (with-slots (thumb-pixmap thumb-size pixels-per-unit) self
  584.     ;; Discard old image --- recreate upon display
  585.     (when thumb-pixmap
  586.       (free-pixmap thumb-pixmap)
  587.       (setf thumb-pixmap nil))
  588.     (setf thumb-size (round (* new-indicator-size pixels-per-unit)))))
  589.  
  590.  
  591.  
  592. ;;;----------------------------------------------------------------------------------+
  593. ;;;                                                                                  |
  594. ;;;                                     vslider                                      |
  595. ;;;                                                                                  |
  596. ;;;----------------------------------------------------------------------------------+
  597.  
  598. (defcontact vslider (slider)
  599.   ()
  600.   (:documentation    "A vertically-oriented slider valuator."))
  601.  
  602. ;;; Indicator control
  603.  
  604. (defmethod valuator-erase-indicator ((self vslider))
  605.   (with-slots (thumb-position width thumb-size) self
  606.     (clear-area self
  607.         :y      thumb-position
  608.         :width  width
  609.         :height thumb-size)))
  610.  
  611.  
  612. ;;; Display (fix this!)
  613.  
  614. ;(DEFMETHOD valuator-display-indicator ((self vslider))
  615. ;  (WITH-SLOTS (thumb-pixmap width thumb-size depth contact-background fg-color bg-color thumb-position) self
  616. ;    (USING-GCONTEXT (gcontext :foreground fg-color
  617. ;                  :background bg-color
  618. ;                  :fill-style :solid)
  619. ;      (UNLESS thumb-pixmap
  620. ;    ;; Create slider thumb pixmap
  621. ;    (SETF thumb-pixmap (create-pixmap :drawable self
  622. ;                      :width    width
  623. ;                      :height   thumb-size
  624. ;                      :depth    depth))
  625. ;    (LET* ((offset       (ROUND (MIN width thumb-size) 8))
  626. ;           (offset2      (ROUND offset 2))
  627. ;           (face-left    0)
  628. ;           (face-top     offset2)
  629. ;           (face-right   (- width offset))
  630. ;           (face-bottom  (- thumb-size offset2))
  631. ;           (shadow-width (MIN 3 (ROUND offset 3))))    
  632.       
  633. ;      ;; Draw background
  634. ;      (TYPECASE contact-background
  635. ;        (pixmap (WITH-GCONTEXT
  636. ;              (gcontext :fill-style :tiled :tile contact-background)
  637. ;              (DRAW-RECTANGLE thumb-pixmap gcontext 
  638. ;                      0 0
  639. ;                      width thumb-size :fill-p)))
  640. ;        (t      (WITH-GCONTEXT
  641. ;              (gcontext :fill-style :solid :foreground contact-background)
  642. ;              (DRAW-RECTANGLE thumb-pixmap gcontext 
  643. ;                      0 0
  644. ;                      width thumb-size :fill-p))))
  645.       
  646. ;      ;; Draw shadow
  647. ;      (WITH-GCONTEXT
  648. ;        (gcontext :fill-style :solid)
  649. ;        (DRAW-RECTANGLE thumb-pixmap gcontext 
  650. ;                shadow-width shadow-width
  651. ;                (- width shadow-width) (- thumb-size shadow-width) :fill-p))
  652.       
  653. ;      ;; Draw sides    
  654. ;      (WITH-GCONTEXT            ;top
  655. ;        (gcontext :fill-style :opaque-stippled :stipple (cluei:get-pixmap (root self) 25%gray))
  656. ;        (DRAW-LINES thumb-pixmap gcontext
  657. ;            (LIST face-right face-top
  658. ;                  width      0
  659. ;                  0          0
  660. ;                  face-left  face-top)
  661. ;            :fill-p t :shape :convex))
  662.       
  663. ;      (WITH-GCONTEXT            ;bottom
  664. ;        (gcontext :fill-style :opaque-stippled :stipple (cluei:get-pixmap (root self) 66%gray))
  665. ;        (DRAW-LINES thumb-pixmap gcontext
  666. ;            (LIST width      thumb-size
  667. ;                  0          thumb-size
  668. ;                  face-left  face-bottom
  669. ;                  face-right face-bottom)
  670. ;            :fill-p t :shape :convex)
  671. ;        (DRAW-LINES thumb-pixmap gcontext    ;right
  672. ;            (LIST width      thumb-size
  673. ;                  face-right face-bottom
  674. ;                  face-right face-top
  675. ;                  width 0)
  676. ;            :fill-p t :shape :convex))
  677.       
  678. ;      ;; Draw top
  679. ;      (WITH-GCONTEXT (gcontext :line-style :solid)
  680. ;        (DRAW-RECTANGLE thumb-pixmap gcontext 0 0 width thumb-size))
  681. ;      (WITH-GCONTEXT
  682. ;        (gcontext :fill-style :opaque-stippled :stipple (cluei:get-pixmap (root self) 12%gray))
  683. ;        (DRAW-RECTANGLE thumb-pixmap gcontext 
  684. ;                face-left face-top
  685. ;                (- face-right face-left) (- face-bottom face-top) :fill-p))
  686.       
  687. ;      ;; Draw notches
  688. ;      (LET* ((number-notches 1)
  689. ;         (notch-height (ROUND (- face-bottom face-top) 15))
  690. ;         (notch-y      (+ face-top
  691. ;                  (ROUND (- face-bottom face-top) (1+ number-notches))
  692. ;                  (ROUND notch-height 2)))
  693. ;         (notch-y-nh   (- notch-y notch-height))
  694. ;         (notch-y-nh2  (- notch-y (ROUND notch-height 2)))
  695. ;         (notch-x      (ROUND (- face-right face-left) 15))
  696. ;         (fl-nx        (+ face-left notch-x))
  697. ;         (w-nx         (- width notch-x)))
  698. ;        (DOTIMES (i number-notches)
  699. ;          (TYPECASE contact-background
  700. ;        (pixmap (WITH-GCONTEXT
  701. ;              (gcontext :fill-style :tiled :tile contact-background)
  702. ;              (DRAW-LINES thumb-pixmap gcontext
  703. ;                      (LIST face-left notch-y
  704. ;                        fl-nx     notch-y-nh2
  705. ;                        face-left notch-y-nh)
  706. ;                      :fill-p t :shape :convex)))
  707. ;        (t      (WITH-GCONTEXT
  708. ;              (gcontext :fill-style :solid :foreground contact-background)
  709. ;              (DRAW-LINES thumb-pixmap gcontext
  710. ;                      (LIST face-left notch-y
  711. ;                        fl-nx     notch-y-nh2
  712. ;                        face-left notch-y-nh)
  713. ;                      :fill-p t :shape :convex))))        
  714. ;          (WITH-GCONTEXT
  715. ;        (gcontext :fill-style :opaque-stippled :stipple (cluei:get-pixmap (root self) 88%gray))
  716. ;        (DRAW-LINES thumb-pixmap gcontext
  717. ;                (LIST face-left notch-y-nh
  718. ;                  w-nx      notch-y-nh              
  719. ;                  width     notch-y-nh2
  720. ;                  fl-nx     notch-y-nh2)
  721. ;                :fill-p t :shape :convex))                
  722. ;          (WITH-GCONTEXT
  723. ;        (gcontext :fill-style :opaque-stippled :stipple (cluei:get-pixmap (root self) 33%gray))
  724. ;        (DRAW-LINES thumb-pixmap gcontext
  725. ;                (LIST w-nx      notch-y
  726. ;                  face-left notch-y              
  727. ;                  fl-nx     notch-y-nh2
  728. ;                  width     notch-y-nh2)
  729. ;                :fill-p t :shape :convex))                
  730. ;          (WITH-GCONTEXT
  731. ;        (gcontext :line-style :solid)
  732. ;        (DRAW-LINES thumb-pixmap gcontext
  733. ;                (LIST face-left notch-y
  734. ;                  fl-nx     notch-y-nh2
  735. ;                  face-left notch-y-nh
  736. ;                  w-nx      notch-y-nh
  737. ;                  width     notch-y-nh2
  738. ;                  w-nx      notch-y
  739. ;                  face-left notch-y)))        
  740. ;          (INCF notch-y (ROUND (- face-bottom face-top) 4))
  741. ;          )))))
  742. ;    ;; Display thumb-pixmap
  743. ;    (WITH-GCONTEXT
  744. ;      (gcontext :fill-style :tiled :tile thumb-pixmap)
  745. ;      (DRAW-RECTANGLE self gcontext
  746. ;    0      thumb-position
  747. ;    width  thumb-size
  748. ;    :fill-p))))
  749.  
  750. ;;; Size control
  751.  
  752. (defmethod valuator-adjust-size ((self vslider) new-minimum new-maximum  new-indicator-size)
  753.   "Adjust internal data for new range and indicator size."
  754.   (with-slots (height pixels-per-unit) self
  755.     (setf pixels-per-unit (/ height (+ new-maximum (- new-minimum)  new-indicator-size)))))
  756.  
  757.  
  758.  
  759.  
  760.  
  761. ;;; Actions
  762.  
  763. (defmethod move-here ((self vslider))
  764.   "Change value according to position given by the EVENT."
  765.   (with-event (y)
  766.     (with-slots (value minimum maximum event-y pixels-per-unit indicator-size precision) self
  767.       (let ((new-value (max (min (precision-round
  768.                    (+ minimum (/ y pixels-per-unit) (round indicator-size -2))
  769.                    precision)
  770.                                  maximum)
  771.                             minimum)))      
  772.         (when (/= new-value value)
  773.           (valuator-set-by-user self new-value))))))
  774.